<?PHP
function center_block_regional_show(){

	global $xoopsDB, $xoopsModule, $xoopsConfig, $xoopsModuleConfig;

		//GET MOD CONFIG STUFF
		if (!isset($GLOBALS['xoopsModuleConfig']) || $GLOBALS['xoopsModule']->getVar('dirname') != "local_news") {
		  $modhandler = &xoops_gethandler('module');
		  $module = &$modhandler->getByDirname("local_news");
		  $config_handler = &xoops_gethandler('config');
		  $xoopsModuleConfig = &$config_handler->getConfigsByCat(0,$module->getVar('mid')); 
		  $enableSyndication = $xoopsModuleConfig['enableSyndication'];
		  $inModule = 0;
		}else {
		  $enableSyndication = $xoopsModuleConfig['enableSyndication'];
		  $inModule = 1;
		  return false;//don't return this block if it is in the local_news module itself... will blow up.
		}
		//END GET MOD CONFIG STUFF
		
		
		
		//FUNCTION HANDLE IMAGE URLS
		function getImageUrlReg($image,$TN=false){
	    //global $xoopsModule;
		if(!ereg('http', $image) && $TN==false){
			return XOOPS_URL."/modules/local_news/media/pictures/".$image;
		}elseif($TN==false){
			return $image;
		}elseif(!ereg('http', $image) && $TN==true){
			return XOOPS_URL."/modules/local_news/media/pictures/".substr_replace($image, '-TN.jpg', -4);
		}else{
			return substr_replace($image, '-TN.jpg', -4);
		}
	  }
		
		
		
	//GET SYNDICATED NEWS STORIES
	if($enableSyndication == 1){
		  $syndication = array();			
			$link = mysql_connect($xoopsModuleConfig['syndicationDB_Host'], $xoopsModuleConfig['syndicationDB_User'], $xoopsModuleConfig['syndicationDB_Passaword']) or ($error = mysql_error());
			$Query = "SELECT * FROM CA_SE_News WHERE storyID NOT LIKE '".strtoupper($xoopsModuleConfig['stationLetters'])."%' AND expiration_date > '".mktime()."' AND publish_date < '".mktime(23,59,59,date("m"),date("d"),date("Y"))."' AND soundfile != '' ORDER BY publish_date DESC,ID DESC LIMIT ".$xoopsModuleConfig['NICR']."";
			mysql_select_db($xoopsModuleConfig['syndicationDB']) or ($error = "Could not select database");
			  $result = mysql_query ($Query, $link) or ($error = "Query failed");
	
		if ($result){
					while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
						$syndication['headline'][] = $row['headline'];
						$syndication['ID'][] = $row['ID'];
						$syndication['storyID'][] = $row['storyID'];
						$syndication['byline'][] = $row['byline'];
						$syndication['dateline'][] = $row['dateline'];
						$syndication['tease'][] = $row['tease'];
						$syndication['copyright'][] = $row['copyright'];
						$syndication['copyrightdate'][] = date("Y",$row['publish_date']);
						$syndication['publish_date'][] = date("Y-m-d",$row['publish_date']);
						if($row['image']){
							$syndication['image'][] = getImageUrlReg($row['image']);
							$syndication['imageTN'][] = getImageUrlReg($row['image'],true);
							$syndication['imageTNwidth'][] = $row['imageTNwidth'];
						}else{
							$syndication['image'][] = "";
							$syndication['imageTN'][] = "";
							$syndication['imageTNwidth'][] = "";
						}
						$syndication['credit'][] = $row['credit'];
						$syndication['caption'][] = $row['caption'];
						$syndication['body'][] = $row['body'];
					}
					
						mysql_free_result($result);
						mysql_close ($link);
						
				
					if(isset($syndication['headline']) && count($syndication['headline']) > 0){
					$tempSyndication=array();
					for($i=0; $i < count($syndication['storyID']); $i++){
						$tempSyndication[] = array("body"=>$syndication['body'][$i],"caption"=>$syndication['caption'][$i],"credit"=>$syndication['credit'][$i],"image"=>$syndication['image'][$i],"imageTN"=>$syndication['imageTN'][$i],"imageTNwidth"=>$syndication['imageTNwidth'][$i],"publish_date"=>$syndication['publish_date'][$i],"copyrightdate"=>$syndication['copyrightdate'][$i],"copyright"=>$syndication['copyright'][$i],"tease"=>$syndication['tease'][$i],"dateline"=>$syndication['dateline'][$i],"byline" => $syndication['byline'][$i],"headline"=>$syndication['headline'][$i],"ID"=>$syndication['ID'][$i],"storyID"=>$syndication['storyID'][$i]);
					}
					 //return the bugger
					 $all = array("data" => $tempSyndication,"inModule" => $inModule,"useImages" => $xoopsModuleConfig['centerblock_showImages'],"linkIsImage" => $xoopsModuleConfig['centerblock_LinkIsImage'],"showCopyright" => $xoopsModuleConfig['centerblock_ShowCopyright']);
					 return $all;
					}else{
					 return false;
					}

					
		}else{
			return false;
		}//end $result if
			
		  
	}else{
	return false;
	}//end syndication if
	



	
}

?>